var subpages = ['main-home.html', 'main-message.html', 'main-contact.html', 'main-setting.html'];
var subpage_style = {
	top: '45px',
	bottom: '51px'
};
document.addEventListener('plusready', function() {
	var self = plus.webview.currentWebview();
	for(var i = 0; i < 4; i++) {
		var sub = plus.webview.create(subpages[i], subpages[i], subpage_style);
		if(i > 0) {
			sub.hide();
		}
		self.append(sub);
	}
});
//当前激活选项
var activeTab = subpages[0];
var title = document.getElementById("title");
//选项卡点击事件
mui('.mui-bar-tab').on('tap', 'a', function(e) {
	var targetTab = this.getAttribute('id');
	if(targetTab == activeTab) {
		return;
	}
	//更换标题
	title.innerHTML = this.querySelector('.mui-tab-label').innerHTML;
	//显示目标选项卡
	plus.webview.show(targetTab);
	//隐藏当前;
	plus.webview.hide(activeTab);
	//更改当前活跃的选项卡
	activeTab = targetTab;
	mui.fire(plus.webview.getWebviewById(activeTab), 'show');
});
var backButtonPress = 0;
mui.back = function(event) {
	backButtonPress++;
	if(backButtonPress > 1) {
		plus.runtime.quit();
	} else {
		mui.toast('再按一次退出应用');
	}
	setTimeout(function() {
		backButtonPress = 0;
	}, 1000);
	return false;
};